import TurnedOnLight from '@/assets/screenShowImg/img/开灯.png'
import TurnedOffLight from '@/assets/screenShowImg/img/关灯.png'
import OfflineLight from '@/assets/screenShowImg/img/离线灯.png'
import OnlineGateway from '@/assets/screenShowImg/img/网关在线.png'
import OfflineGateway from '@/assets/screenShowImg/img/网关离线.png'
import OnOpticalSensor from '@/assets/screenShowImg/img/传感器/光感开.png'
import OffOpticalSensor from '@/assets/screenShowImg/img/传感器/光感关.png'
import OfflineOpticalSensor from '@/assets/screenShowImg/img/传感器/光感离线.png'
import ControlDevice from '@/assets/screenShowImg/img/控制.png'

// 根据 productKey、在线状态和开关状态获取设备图标路径
export const getDeviceIconPath = (productKey: string, online: boolean, switchState: number = 0): string => {
  switch (true) {
    case isGateway(productKey):
      return online ? OnlineGateway : OfflineGateway
    case isLightController(productKey):
      return online 
        ? switchState === 1 ? TurnedOnLight : TurnedOffLight 
        : OfflineLight
    case isOpticalSensor(productKey):
      return online 
        ? switchState === 1 ? OnOpticalSensor : OffOpticalSensor 
        : OfflineOpticalSensor
    default:
      return ControlDevice
  }
}

// 定义返回值类型
export interface DeviceProperties {
  swName: string;
  slName: string;
  gwmac?: string;
}

// 设备属性映射配置
const devicePropertyMap: Record<string, DeviceProperties> = {
  'Bwmac6pph45mSTFY': { // 4G单灯控制器
    swName: 'lamp_onoff',
    slName: 'lamp_bright'
  },
  'fHnYRFCEhDe5Z6he': { // 4G灯控制电源(新创)
    swName: 'lamp_onoff',
    slName: 'lamp_bright'
  },
  'fKwZ8dkErkpSJKEr': { // 4G灯控制电源(福硕)
    swName: 'lamp_onoff',
    slName: 'lamp_bright'
  },
  'fMeiBGaMcjiQiGiR': { // 技象Lora单灯控制器
    swName: 'SwState',
    slName: 'LampBright'
  },
  'hATm2Tswh3TDik8W': { // 微自然单灯控制器
    swName: 'pa0',
    slName: 'duty0',
    // 这里先留空，在组件里单独处理动态获取
    gwmac: '' 
  }
}

// 默认配置
const defaultProperties: DeviceProperties = {
  swName: '',
  slName: '',
  gwmac: ''
}

// 根据 productKey 获取设备属性的公共方法
export const getDeviceProperties = (productKey: string): DeviceProperties => {
  return devicePropertyMap[productKey] || defaultProperties;
}

// 判断是否为灯控制器
export const isLightController = (productKey: string): boolean => {
  switch (productKey) {
    case 'Bwmac6pph45mSTFY': // 4G单灯控制器
    case 'fHnYRFCEhDe5Z6he': // 4G灯控制电源(新创)
    case 'fKwZ8dkErkpSJKEr': // 4G灯控制电源(福硕)
    case 'fMeiBGaMcjiQiGiR': // 技象Lora单灯控制器
    case 'hATm2Tswh3TDik8W': // 微自然单灯控制器
      return true
    default:
      return false
  }
}

// 判断是否为网关
export const isGateway = (productKey: string): boolean => {
  switch (productKey) {
    case 'sfFiZ4Xmd5axJt3Y': // 技象Lora网关
    case '7GhmGTj27mehmpaJ': // 微自然网关
      return true
    default:
      return false
  }
}

// 判断是否为光照度传感器
export const isOpticalSensor = (productKey: string): boolean => {
  switch (productKey) {
    case 'QJHw22tkkdPB3QXK': // 光照度传感器
      return true
    default:
      return false
  }
}